<?php

class Book {
    public $id;
    public $title;
    public $author;
    public $publisher;
    public $img_url;
    public $price;
    public $category;

    public static function fromArray(array $book_data): Book {
        $book = new Book;

        $book->id        = $book_data[0];
        $book->title     = $book_data[1];
        $book->author    = $book_data[2];
        $book->publisher = $book_data[3];
        $book->category  = $book_data[4];
        $book->price     = $book_data[5];
        $book->img_url   = $book_data[6];
        
        return $book;
    }
}

class User {
    var $id;
    var $name;
    var $passwd;
    var $email;
}

class CartItem {
    var $bookID;
    var $cnt;

    public static function fromArray(array $cart_data): CartItem {
        $cart = new CartItem;

        $cart->bookID = $cart_data[0];
        $cart->cnt    = $cart_data[1];

        return $cart;
    }
}

class Addr {
    var $id;
    var $addr;
    var $is_default;

    public static function fromArray(array $addr_data): Addr {
        $addr = new Addr;

        $addr->id         = $addr_data[0];
        $addr->addr       = $addr_data[1];
        $addr->is_default = $addr_data[2];

        return $addr;
    }
}

class Comment {
    // maybe_unused
    var $id;
    var $username;
    var $content;
    var $score;

    public static function fromArray(array $comment_data): Comment {
        $comment = new Comment;

        $comment->id      = $comment_data[0];
        $comment->username = $comment_data[1];
        $comment->content = $comment_data[2];
        $comment->score   = $comment_data[3];

        return $comment;
    }
}

class OrderBook {
    var $id;
    var $cnt;

    public static function fromArray(array $data): OrderBook {
        $order_book = new OrderBook;

        $order_book->id  = $data[0];
        $order_book->cnt = $data[1];

        return $order_book;
    }
}

class Order {
    var $id;
    var $time;
    var $addr;
    var $status;
    var $books;

    public static function fromArray(array $data): Order {
        $order = new Order;

        $order->id      = $data[0];
        $order->time    = $data[1];
        $order->status  = $data[2];
        $order->addr    = $data[3];
        $order->books   = [];

        return $order;
    }

    public function addBook(OrderBook $book) {
        array_push($this->books, $book);
    }
}

?>